package net.rock.service;

import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import net.rock.pojo.Address;
import net.rock.mapper.AddressMapper;
import java.util.List;


@Service
public class AddressService {
	@Autowired
    private AddressMapper addressMapper;

	public List<Address> showAddress(int userId) {
		return addressMapper.showAddress(userId);
	}

    public void add(Address address) {
    	if (address.isDefault()) {
    		addressMapper.unsetDefault(address.getUserId());
		}
        addressMapper.add(address);
    }

    public void del(Address address){
        addressMapper.del(address);
    } 

    public void edit(Address address){
        if (address.isDefault()) {
            addressMapper.unsetDefault(address.getUserId());
        }
        addressMapper.edit(address);
    }
	
}
